package com.javer.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.javer.dao.CommDao;
import com.javer.dao.CommentDao;
import com.javer.dao.CompanyDao;
import com.javer.dao.KeyValDao;
import com.javer.domain.Comment;
import com.javer.domain.Company;
import com.javer.domain.KeyVal;
import com.javer.domain.PageView;

@Service
public class CompanyService {
	@Autowired private CompanyDao companyDao;
	@Autowired private CommentDao commentDao;
	@Autowired private KeyValDao keyValDao;	
	@Autowired private CommDao commDao;

	public void deleteCompany(int id) {
		commDao.deleteByIds("company", new int[]{id});
		commDao.deleteByProperty("comment", "tid", String.valueOf(id));
	}
	
	public void getCompanyByPage(PageView<Company> pv) {
		companyDao.getCompanyByPage(pv);
	}
	
	public PageView<Company> findCompany(PageView<Company> pv, String name) {
		return companyDao.findCompany(pv, name);
	}
	
	public void addCompanyNameKeyword(KeyVal kv) {
		keyValDao.addKeyVal(kv); // 保存查询关键字
	}
	
	public List<KeyVal> getHotCompanyNameKeyword(String name, int limit) {
		return keyValDao.getHotCompanyKeyword(name, limit);
	}
	
	public List<Comment> getNewComment(int limit) {
		return commentDao.getNewComment(limit);
	}
	
	public List<Comment> getCommentsByCompany(int id) {
		return commentDao.getCommentsById(id, 0);
	}
	
	public List<Comment> getHotCommentsByCompany(int id) {
		return commentDao.getHotCommentsById(id, 0);
	}
	
	public PageView<Company> getGoodCompany(PageView<Company> pv) {
		return companyDao.getGoodCompany(pv);
	}
	
	public PageView<Company> getBadCompany(PageView<Company> pv) {
		return companyDao.getBadCompany(pv);
	}
	
	public PageView<Company> getNewCompany(PageView<Company> pv) {
		return companyDao.getNewCompany(pv);
	}
	
	public PageView<Company> getHotCompany(PageView<Company> pv) {
		return companyDao.getHotCompany(pv);
	}
	
	public List<Company> getGoodCompany(int limit) {
		return companyDao.getGoodCompany(limit);
	}
	
	public List<Company> getBadCompany(int limit) {
		return companyDao.getBadCompany(limit);
	}
	
	public List<Company> getNewCompany(int limit) {
		return companyDao.getNewCompany(limit);
	}
	
	public List<Company> getHotCompany(int limit) {
		return companyDao.getHotCompany(limit);
	}
	
	public void updateCompanyScore(Company company) {
		companyDao.updateCompanyScore(company);
	}
	
	public void addCompanyComment(Company company, Comment comment) {
		comment.setCtype(0);
		commentDao.addComment(comment);
		if (company.getCscore() != 0) {
			companyDao.updateCompanyScore(company);
		}
	}
	
	public int addCompany(Company company) {
		return companyDao.addCompany(company);
	}
	
	public void updateCompany(Company company) {
		companyDao.updateCompany(company);
	}
	
	public Company getCompanyById(int id) {
		return companyDao.getCompanyById(id);
	}
	
	public List<Company> getAllCompany() {
		return companyDao.getAllCompany();
	}
}
